# encoding:utf-8
import csv
from config.all_paths import allure_report_suites

def writeCSV(filepath, data, mode='w'):
    """
    写入 CSV 文件。
    :param filepath: 目标文件路径
    :param data: 要写入的二维列表数据[[],[]]
    :param mode: 写入模式 ('w' 覆盖, 'a+' 追加)
    """
    with open(filepath, mode, newline='', encoding='utf8') as file:
        writer = csv.writer(file)
        writer.writerows(data)

def readCSV(filepath):
    """
    循环获取每一行的数据，返回列表格式的数据:[[],[],[]]
    第一个元素是头部
    """
    with open(filepath, 'r',encoding='utf8') as file:
        reader = csv.reader(file, delimiter=',')
        return list(reader)

def readCSVToDict(filepath):
    """
    读取 CSV 数据，返回字典列表: [{}, {}, {}]
    """
    with open(filepath, encoding='utf-8') as fp:
        return list(csv.DictReader(fp))


if __name__ == '__main__':
    print(readCSVToDict(allure_report_suites))
